var express = require('express');
var router = express.Router();

const collection = require("../models/collection")

const formidable = require('formidable');

router.post('/', (req, res, next) => {
    var form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
        if (err) {
            res.json({ 'state': false })
        } else {
            collection.find({
                UUID: fields.UUID,
                question_ID: fields.question_ID
            }, {
                attachment: 1,
                question_ID: 1, // point_id 
                _id: 0
            }, (error, id_list) => {
                if (error) {
                    res.json({ 'state': false, 'msg': error });
                } else {
                  if(id_list.length !== 0){
                    res.json({ 'state': true, 'isCollectioned': true })
                  } else {
                    res.json({ 'state': true, 'isCollectioned': false })
                  }
                }
            })
        }

    });

});

module.exports = router;